package com.wolfking.converter.service;


import com.wolfking.converter.entity.SqlDataSource;
import com.wolfking.converter.entity.SqlDefine;
import com.wolfking.converter.entity.SqlDefineParam;
import com.wolfking.converter.entity.SqlFieldTransform;
import com.wolfking.converter.spring.ConverterInterface;
import com.wolfking.converter.spring.ConverterMethod;
import com.wolfking.converter.spring.SqlParam;

import java.util.List;

@ConverterInterface
public interface SqlConfigInterface {

    String SQL_DEFINE_SELECT_FIELD = "select id,define_key as defineKey,data_source as dataSource,"
            + "IFNULL(from_base64(`sql_base64`),sql_base64) as `sqlBase64`,hide_columns as hideColumns,"
            + "IFNULL(from_base64(`count_sql_base64`),count_sql_base64) as `countSqlBase64`, html_center_show as `htmlCenterShow`,"
            + "sql_describe as sqlDescribe,under_line_to_camel as underLineToCamel,allow_empty_param_query as allowEmptyParamQuery,"
            + "create_time as createTime,update_time as updateTime,version ,param_verify as paramVerify,auto_web_load as `autoWebLoad`"
            + "from sql_define ";


    @ConverterMethod(sql = "select id,define_key as defineKey,param_name as paramName,"
            + "param_type as paramType,converter, `sort`, drop_down_class as dropDownClass,"
            + "format,required,param_describe as `paramDescribe`,"
            + "IFNULL(from_base64(`expression`),expression) as `expression`,"
            + "page_num as pageNum,page_size as pageSize,default_value as defaultValue,"
            + "drop_down as dropDown,create_time as createTime,update_time as updateTime,version "
            + "from sql_define_param where define_key = :key")
    List<SqlDefineParam> querySqlDefineParam(@SqlParam("key") String key);

    @ConverterMethod(sql = SQL_DEFINE_SELECT_FIELD + " where define_key = :key limit 1")
    SqlDefine querySqlDefineByKey(@SqlParam("key") String key);

    @ConverterMethod(sql = SQL_DEFINE_SELECT_FIELD)
    List<SqlDefine> querySqlDefineList();

    String SQL_FIELD_TRANSFORM_SELECT_FIELD = "select `id` as `id`\n" +
            ",`define_key` as `defineKey`\n" +
            ",`field_name` as `fieldName`\n" +
            ",`transform` as `transform`\n" +
            ",`construct_arg` as `constructArg`\n" +
            ",`create_time` as `createTime`\n" +
            ",`update_time` as `updateTime`\n" +
            ",`version` as `version`\n" +
            " from sql_filed_transform";

    @ConverterMethod(sql = SQL_FIELD_TRANSFORM_SELECT_FIELD + " where define_key = :key")
    List<SqlFieldTransform> getSqlFiledTransformByKey(@SqlParam("key") String key);


    String DATA_SOURCE_SELECT_FIELD = "select `id` as `id`\n" +
            ",`name` as `name`\n" +
            ",`driver_class_name` as `driverClassName`\n" +
            ",`url` as `url`\n" +
            ",`username` as `username`\n" +
            ",`password` as `password`\n" +
            ",`initial_size` as `initialSize`\n" +
            ",`max_active` as `maxActive`\n" +
            ",`min_idle` as `minIdle`\n" +
            ",`max_idle` as `maxIdle`\n" +
            ",`max_wait` as `maxWait`\n" +
            ",`keep_alive` as `keepAlive`\n" +
            ",`test_while_idle` as `testWhileIdle`\n" +
            ",`validation_query` as `validationQuery`\n" +
            ",`test_on_borrow` as `testOnBorrow`\n" +
            ",`test_on_return` as `testOnReturn`\n" +
            ",`pool_prepared_statements` as `poolPreparedStatements`\n" +
            ",`create_time` as `createTime`\n" +
            ",`update_time` as `updateTime`\n" +
            ",`is_able` as `isAble`\n" +
            ",`version` as `version`\n" +
            " from sql_data_source";

    @ConverterMethod(sql = DATA_SOURCE_SELECT_FIELD)
    List<SqlDataSource> queryDataSource();

}
